home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / perl5 / MooseX / LazyRequire.pm < prev    next >
Encoding:
Perl POD Document  |  2010-07-18  |  2.0 KB  |  94 lines

  1. package MooseX::LazyRequire;
  2. BEGIN {
  3.   $MooseX::LazyRequire::AUTHORITY = 'cpan:FLORA';
  4. }
  5. BEGIN {
  6.   $MooseX::LazyRequire::VERSION = '0.06';
  7. }
  8. # ABSTRACT: Required attributes which fail only when trying to use them
  9.  
  10. use Moose 0.94 ();
  11. use Moose::Exporter;
  12. use aliased 0.30 'MooseX::LazyRequire::Meta::Attribute::Trait::LazyRequire';
  13. use namespace::autoclean;
  14.  
  15.  
  16. Moose::Exporter->setup_import_methods(
  17.     class_metaroles => {
  18.         attribute => [LazyRequire],
  19.     },
  20. );
  21.  
  22. 1;
  23.  
  24.  
  25. __END__
  26. =pod
  27.  
  28. =encoding utf-8
  29.  
  30. =head1 NAME
  31.  
  32. MooseX::LazyRequire - Required attributes which fail only when trying to use them
  33.  
  34. =head1 SYNOPSIS
  35.  
  36.     package Foo;
  37.  
  38.     use Moose;
  39.     use MooseX::LazyRequire;
  40.  
  41.     has foo => (
  42.         is            => 'ro',
  43.         lazy_required => 1,
  44.     );
  45.  
  46.     has bar => (
  47.         is      => 'ro',
  48.         builder => '_build_bar',
  49.     );
  50.  
  51.     sub _build_bar { shift->foo }
  52.  
  53.  
  54.     Foo->new(foo => 42); # succeeds, foo and bar will be 42
  55.     Foo->new(bar => 42); # succeeds, bar will be 42
  56.     Foo->new;            # fails, neither foo nor bare were given
  57.  
  58. =head1 DESCRIPTION
  59.  
  60. This module adds a C<lazy_required> option to Moose attribute declarations.
  61.  
  62. The reader methods for all attributes with that option will throw an exception
  63. unless a value for the attributes was provided earlier by a constructor
  64. parameter or through a writer method.
  65.  
  66. =head1 CAVEATS
  67.  
  68. Apparently Moose roles don't have an attribute metaclass, so this module can't
  69. easily apply its magic to attributes defined in roles. If you want to use
  70. C<lazy_required> in role attributes, you'll have to apply the attribute trait
  71. yourself:
  72.  
  73.     has foo => (
  74.         traits        => ['LazyRequire'],
  75.         is            => 'ro',
  76.         lazy_required => 1,
  77.     );
  78.  
  79. =for Pod::Coverage init_meta
  80.  
  81. =head1 AUTHOR
  82.  
  83. Florian Ragwitz <rafl@debian.org>
  84.  
  85. =head1 COPYRIGHT AND LICENSE
  86.  
  87. This software is copyright (c) 2010 by Florian Ragwitz.
  88.  
  89. This is free software; you can redistribute it and/or modify it under
  90. the same terms as the Perl 5 programming language system itself.
  91.  
  92. =cut
  93.  
  94.